package com.hyx.api.controller.pc_admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hyx.api.domain.bo.VerifyModelOptionBo;
import com.hyx.api.domain.vo.VerifyModelOptionVo;
import com.hyx.api.service.pc_admin.IVerifyModelOptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 验机选项Controller
 *
 * @author HK
 * @date 2023-10-21
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/option")
public class VerifyModelOptionController extends BaseController {
    private final IVerifyModelOptionService verifyModelOptionService;

    /**
     * 查询验机选项列表
     */
    @PreAuthorize("@ss.hasPermi('option:option:list')")
    @GetMapping("/list")
    public AjaxResult list(VerifyModelOptionBo bo) {
        return AjaxResult.success(verifyModelOptionService.selectVerifyModelOptionList(bo));
    }

    /**
     * 导出验机选项列表
     */
    @PreAuthorize("@ss.hasPermi('option:option:export')")
    @Log(title = "验机选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VerifyModelOptionBo bo) {
        List<VerifyModelOptionVo> list = verifyModelOptionService.selectVerifyModelOptionList(bo);
        ExcelUtil<VerifyModelOptionVo> util = new ExcelUtil<>(VerifyModelOptionVo.class);
        util.exportExcel(response, list, "验机选项数据");
    }

    /**
     * 获取验机选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('option:option:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(verifyModelOptionService.selectVerifyModelOptionById(id));
    }

    /**
     * 新增验机选项
     */
    @PreAuthorize("@ss.hasPermi('option:option:add')")
    @Log(title = "验机选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody VerifyModelOptionBo bo) {
        return toAjax(verifyModelOptionService.insertVerifyModelOption(bo));
    }

    /**
     * 修改验机选项
     */
    @PreAuthorize("@ss.hasPermi('option:option:edit')")
    @Log(title = "验机选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody VerifyModelOptionBo bo) {
        return toAjax(verifyModelOptionService.updateVerifyModelOption(bo));
    }

    /**
     * 删除验机选项
     */
    @PreAuthorize("@ss.hasPermi('option:option:remove')")
    @Log(title = "验机选项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(verifyModelOptionService.deleteVerifyModelOptionByIds(ids));
    }
}
